package com.gjr.demo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.gjr.eduservice.EduApplication;
import com.gjr.eduservice.entity.EduTeacher;
import com.gjr.eduservice.mapper.EduTeacherMapper;
import com.gjr.eduservice.service.EduTeacherService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;

import java.text.SimpleDateFormat;
import java.util.*;

@SpringBootTest(classes = EduApplication.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class Demo {
    @Autowired
    private EduTeacherMapper eduTeacherMapper;
    @Autowired
    private EduTeacherService eduTeacherService;

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Test
    public void test1() {
        List<EduTeacher> eduTeachers = eduTeacherMapper.selectList(new LambdaQueryWrapper<EduTeacher>()
                .apply("date_format(join_date, '%Y-%m') = {0}", "2019-10"));

        if (!ObjectUtils.isEmpty(eduTeachers)) {
            eduTeachers.stream().forEach(System.out::println);
        }
    }

    @Test
    public void test2() {
        EduTeacher eduTeacher = eduTeacherService.getOne(new LambdaQueryWrapper<EduTeacher>()
                .eq(EduTeacher::getIntro, 1), false);

        System.out.println("eduTeacher：" + eduTeacher);
    }
}
